# 进行一次登录
S.showSignInDialog = ->
    console.log 'showSignInDialog'
    dialog = S.dialog.show {content: ST.SignIn()}

    $username = $('input[name="username"]', dialog.$dialog)
    $username.val(localStorage.getItem('username'))

    $tip = $('.tip', dialog.$dialog)

    $signInBtn = $('.do-sign-in', dialog.$dialog)
    $signInBtn.click ->
        $tip.html '正在登录，请稍后...'
        $signInBtn.hide()

        username = $.trim $username.val()
        password = $.trim $('input[name="password"]', dialog.$dialog).val()

        q = S.api.post 'sign-in?staff=true', {username, password}
        q.then (res)->
            S.user = res
            $tip.html '登录成功'

            localStorage.setItem 'username', username

            S.trigger 'AuthChanged', res

            S.setTimeout 500, -> dialog.close()
        q.catch S.alertAjaxError
        q.catch ->
            $signInBtn.show()